package main

import (
	"github.com/gin-gonic/gin"
	"github.com/micro/go-micro/v2/web"
	"net/http"
	"strconv"
)

/**
docker compose 使用测试demo
实现一个计数器效果
gin + go-micro v2
go get github.com/micro/go-micro/v2
go get github.com/gin-gonic/gin
 */
func main(){
	engine := gin.Default()
	engine.GET("/counter",counterHanlde)

	//创建web包下的服务
	service := web.NewService(
		web.Name("Counter-server"),
		web.Version("v1.0.0"),
		web.Address(":80"),
		)
	//将gin的路由请求交由web服务处理
	service.Handle("/",engine)

	//开启服务监听
	if err:=service.Run();err!=nil{
		panic(err)
	}
}
var counterTime int
func counterHanlde(ctx *gin.Context){
	counterTime ++
	ctx.JSON(http.StatusOK,gin.H{
		"code":1,
		"msg":"success",
		"data":"骚年，你已访问本页"+ strconv.Itoa(counterTime) + "次了!",
	})
}
